package org.ysu.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ysu.entity.Poor;
import org.ysu.service.PoorService;
import org.ysu.vo.ResultVO;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 贫人员表 前端控制器
 * </p>
 *
 * @author LiuJunDa
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/poor")
public class PoorController {

    @Resource
    PoorService poorService;

    @PostMapping("/add")
    public ResultVO<Boolean> add(String poorPeople) {
        return ResultVO.success(poorService.add(poorPeople));
    }

    @GetMapping("/check")
    public ResultVO<Boolean> check(String value,Long id,String field){
        return ResultVO.success(poorService.check(value,id,field));
    }

    @GetMapping("/list")
    public ResultVO<List<Poor>> list(Long fId){
        return  ResultVO.success(poorService.list(fId));
    }

    @PostMapping("/addOne")
    public ResultVO<Boolean> addOne(String idNumber, String name, String nation, Integer sex, Boolean isHead, String relation, String work, Long fId, String health, Boolean insurance, Boolean basic){
        return  ResultVO.success(poorService.addOne(idNumber,name,nation,sex,isHead,relation,work,fId,health,insurance,basic),"添加家庭成员成功");
    }

    @GetMapping("/getById")
    public ResultVO<Poor> getById(Long id){
        return ResultVO.success(poorService.getById(id));
    }

    @PostMapping("/update")
    public ResultVO<Boolean> update(Long id, String idNumber, String name, String nation, Integer sex, Boolean isHead, String relation, String work, Long fId, String health, Boolean insurance, Boolean basic) {
        return ResultVO.success(poorService.update(id,idNumber,name,nation,sex,isHead,relation,work,fId,health,insurance,basic),"修改家庭成员信息成功");
    }

    @PostMapping("/del")
    public ResultVO<Boolean> del(Long id){
        return ResultVO.success(poorService.removeById(id));
    }

    @PostMapping("/setHead")
    public ResultVO<Boolean> setHead(Long id, Long fId){
        return ResultVO.success(poorService.setHead(id,fId));
    }
}
